package com.example.xpvideo.Controller;

import com.example.xpvideo.entity.PageResult;
import com.example.xpvideo.entity.ResponseResult;
import com.example.xpvideo.entity.req.BackOrderReq;
import com.example.xpvideo.entity.req.OrderReq;
import com.example.xpvideo.entity.res.BackstageOrderListRes;
import com.example.xpvideo.entity.res.OrderListRes;
import com.example.xpvideo.enums.ErrCodeEnum;
import com.example.xpvideo.service.OrderService;
import com.example.xpvideo.service.PurchaseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author : 洪俊新
 * @date : 2021/8/9 23:25
 * @description:
 */
@RestController
@RequestMapping("/back/order")
public class OrderController {
    @Autowired
    private PurchaseOrderService purchaseOrderService;
    @Autowired
    private OrderService orderService;

    /**
     * 首页商品列表
     */
    @GetMapping("/list")
    public ResponseResult<PageResult<List<OrderListRes>>> list(OrderReq orderReq)
            throws Exception {
        return purchaseOrderService.list(orderReq);
    }


    /**
     * 后台:订单列表查询
     *
     * @return
     */
    @GetMapping("orderList")
    public ResponseResult<PageResult<List<BackstageOrderListRes>>> backOrderList(@Valid BackOrderReq backOrderReq, BindingResult bindingResult) {
        if (bindingResult.hasErrors()){
            return ResponseResult.responseResult(ErrCodeEnum.unknown_10001, null);
        }
        return orderService.backOrderList(backOrderReq);
    }


    /**
     * 查询订单详情
     * @param orderSn
     * @return
     */
    @GetMapping("orderDetailsInfo")
    public ResponseResult orderDetailsInfo(@RequestParam("orderSn") Integer orderSn) {
        return orderService.orderDetailsInfo(orderSn);
    }
}
